namespace Vanilla.UI

import System

// COLOUR
struct Colour:
	public R as double
	public G as double
	public B as double
	public A as double
	
	static final Black = Colour(0,0,0)
	static final White = Colour(1,1,1)
	
	static final Grey = Colour(0.5,0.5,0.5)
	static final LightGrey = Colour(0.75,0.75,0.75)
	static final DarkGrey = Colour(0.25,0.25,0.25)
	
	static final Blue = Colour(0,0,1)
	static final LightBlue = Colour(0.2,0.6,1)
	static final DarkBlue = Colour(0,0,0.6)
	
	static final Red = Colour(1,0,0)
	
	static final Green = Colour(0,1,0)
	
	static final Yellow = Colour(1,1,0)
	static final GoldenYellow = Colour(1,0.8,0.35)
	
	Lighter as Colour:
		get:
			return op_Multiply(self,1.2)
	
	Darker as Colour:
		get:
			return self * 0.8
	
	def Alpha (a as double):
		return Colour(R,G,B,a*A)
	
	static def op_Multiply (c as Colour, m as double):
		return Colour(c.R*m, c.G*m, c.B*m, c.A)
	
	def constructor (r,g,b,a):
		R = Math.Max(0.0,Math.Min(1.0, r))
		G = Math.Max(0.0,Math.Min(1.0, g))
		B = Math.Max(0.0,Math.Min(1.0, b))
		A = Math.Max(0.0,Math.Min(1.0, a))
	
	def constructor (r,g,b):
		self(r,g,b,1.0)


// KEY
enum Key:
	None
	Enter
	Space
	

// RECTANGLE
struct Rect:
	public X as double
	public Y as double
	public X2 as double
	public Y2 as double
	
	Width as double:
		get:
			return X2 - X
		set:
			X2 = X + value
	
	Height as double:
		get:
			return Y2 - Y
		set:
			Y2 = Y + value
	
	IsInvalid as bool:
		get:
			return double.IsNaN(X) or double.IsNaN(Y) or double.IsNaN(X2) or double.IsNaN(Y2)
	
	def constructor (x as double, y as double, x2 as double, y2 as double):
		X = x
		Y = y
		X2 = x2
		Y2 = y2
	
	def constructor (s as Size):
		self(0, 0, s.Width + 0, s.Height + 0)
	
	def constructor (p as Position, s as Size):
		self(p.X, p.Y, p.X+s.Width, p.Y+s.Height)
	
	override def ToString():
		return "Rect(" + X.ToString() + ", " + Y.ToString() + ", " + X2.ToString() + ", " + Y2.ToString() + ")"
	
	def Round():
		//return self
		return Rect(cast(int,X), cast(int,Y), cast(int,X2), cast(int,Y2))
		//return Rect(cast(int,X*2) / 2, cast(int,Y*2) / 2, cast(int, X2*2) / 2, cast(int, Y2*2) / 2)
	
	static def op_Addition (a as Rect, b as Rect) as Rect:
		return b if a.Width <= 0 or a.Height <= 0
		return a if b.Width <= 0 or b.Height <= 0
		return Rect(Math.Min(a.X,b.X), Math.Min(a.Y,b.Y), Math.Max(a.X2,b.X2), Math.Max(a.Y2,b.Y2))
	
	def Overlaps (r as Rect) as bool:
		return X < r.X2 and Y < r.Y2 and X2 > r.X and Y2 > r.Y

// SIZE
struct Size:
	public Width as double
	public Height as double
	
	def constructor (w as double, h as double):
		Width = w
		Height = h
	
	def constructor (r as Rect):
		self(r.Width, r.Height)
		
	def ToString():
		return "Size(" + Width.ToString() + ", " + Height.ToString() + ")"
	
	def Contains (x as double, y as double) as bool:
		return x >= 0 and y >= 0 and x <= Width and y <= Height
	
	def Rounded (x as int, y as int) as Size:
		try:
			return Size((cast(int,(Width+x))/x)*x, (cast(int,(Height+y))/y)*y)
		except e:
			return self
	
	def Rounded (to as int) as Size:
		return Rounded(to,to)
	
	def Rounded () as Size:
		return Rounded(Width/4, Height/4)
		
// POSITION
struct Position:
	public X as double
	public Y as double
	
	def constructor (x as double, y as double):
		X = x
		Y = y
	
	def constructor (r as Rect):
		self(r.X, r.Y)
	
	def ToString():
		return "Position(" + X.ToString() + ", " + Y.ToString() + ")"
		
// MOUSE BUTTON
enum MouseButton:
	Left = 1
	Middle = 2
	Right = 4

